<?php
// Controller/Default.php

class Controller_Explain extends FLEA_Controller_Action
{
    function actionindex(){
        // $smarty =& $this->_getView();
        // $smarty->display('index.html');
    }
   function actioncreate(){
        if($this->_isPOST()){
            $row['Word'] = $_POST['word'];
            if(empty($row['Word'])){
                js_alert('please input the word!','history.back();');
            }
            $row['YinBiao'] = $_POST['yinbiao'];
            $row['HanYuJieshe'] = iconv("UTF-8","GB18030",$_POST['hanyujieshi']);
            $table_yinbiao = & FLEA::getSingleton('Table_word2yinbiao');
            if($table_yinbiao->create($row)){
                js_alert('更新成功','history.back();');
            }
            else{
                js_alert('更新失败，请重试或联系管理员','history.back();');
            }
        }
        else{
            $smarty =& $this->_getView();
            $smarty->display('createexplain.html');
        }
   }
    function actionedit(){
        if($this->_isPOST()){
            $row['Id'] = (int)$_POST['id'];
            $row['Word'] = $_POST['word'];
            $row['YinBiao'] = $_POST['yinbiao'];
            $row['HanYuJieshe'] = $_POST['hanyujieshi'];
            $row['HanYuJieshe'] = iconv("UTF-8","GB18030",$row['HanYuJieshe']);
            $table_yinbiao = & FLEA::getSingleton('Table_word2yinbiao');
            if($table_yinbiao->save($row)){
                js_alert('更新成功','history.back();');
            }
            else{
                js_alert('更新失败，请重试或联系管理员','history.back();');
            }
        }
        else{
            $id = $_GET['id'];
            if(empty($id)){
                echo 'please input the word';
            }
            $smarty =& $this->_getView();
            $table_sentence =& FLEA::getSingleton('Table_word2yinbiao');
            $sentence = $table_sentence->find((int)$id);
            $sentence[YinBiao] = iconv("GB2312","UTF-8",$sentence[YinBiao]);
            $sentence[HanYuJieshe] = iconv("GB2312","UTF-8",$sentence[HanYuJieshe]);
            $smarty->assign('data', $sentence);
            $smarty->display('editexplain.html');
        }
    }
     function actionlist(){
        $smarty =& $this->_getView();
        $page= (int)$_GET['page'];
        if(empty($page)){
            $page = 1; 
        }
        $table_pics =& FLEA::getSingleton('Table_word2yinbiao');
        FLEA::loadHelper('Pager');
        $pager =& new FLEA_Helper_Pager($table_pics,$page,20,array('status'=>1),null,1);
        $data = $pager->findAll();
        foreach($data as $key => &$value){
            $value['HanYuJieshe'] = iconv("GB2312","UTF-8",$value['HanYuJieshe']);
        }
        $data_page = $pager->getPagerData();
        unset($data_page['pagesNumber']);
        $smarty->assign('data', $data);
        $smarty->assign('data_page', $data_page);
        $smarty->display('explainlist.html');
    }
    function actionlistintrash(){
        $smarty =& $this->_getView();
        $page= (int)$_GET['page'];
        if(empty($page)){
            $page = 1; 
        }
        $table_pics =& FLEA::getSingleton('Table_word2yinbiao');
        FLEA::loadHelper('Pager');
        $pager =& new FLEA_Helper_Pager($table_pics,$page,20,array('status'=>0),null,1);
        $data = $pager->findAll();
        foreach($data as $key => &$value){
            $value['HanYuJieshe'] = iconv("GB2312","UTF-8",$value['HanYuJieshe']);
        }
        $data_page = $pager->getPagerData();
        unset($data_page['pagesNumber']);
        $smarty->assign('data', $data);
        $smarty->assign('data_page', $data_page);
        $smarty->display('explainintrash.html');
    }
     function actiondelintrash(){
        $smarty =& $this->_getView();
        $row['Id']= (int)$_GET['id'];
        if(empty($row['Id'])){
            js_alert("链接错误!",'history.back();');
        }
        $table_pics =& FLEA::getSingleton('Table_word2yinbiao');
        if($table_pics->remove($row)){
            js_alert('彻底删除!','history.back();');
        }
        else{
            js_alert('出错了，请联系管理员','history.back();');
        }
    }
    function actiondel(){
        $smarty =& $this->_getView();
        $row['Id']= (int)$_GET['id'];
        if(empty($row['Id'])){
            js_alert("链接错误!",'history.back();');
        }
        $table_pics =& FLEA::getSingleton('Table_word2yinbiao');
        $row['status'] = 0;
        if($table_pics->save($row)){
            js_alert('成功移除到回收站','history.back();');
        }
        else{
            js_alert('出错了，请联系管理员','history.back();');
        }
     }
    function actionbackfromtrash(){
        $smarty =& $this->_getView();
        $row['Id']= (int)$_GET['id'];
        if(empty($row['Id'])){
            js_alert("链接错误!",'history.back();');
        }
        $table_pics =& FLEA::getSingleton('Table_word2yinbiao');
        $row['status'] = 1;
        if($table_pics->save($row)){
            js_alert('从回收站中恢复','window.close();');
        }
        else{
            js_alert('出错了，请联系管理员','history.back();');
        }
    }
 }
